{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f6ede89e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11 25 36 89]\n",
      "使用for循环：\n",
      "(11+0j)\n",
      "(25+0j)\n",
      "(36+0j)\n",
      "(89+0j)\n",
      "显示二维数组中的数据：\n",
      " [[11 25 36 89]\n",
      " [20 50 60 90]]\n",
      "\n",
      "第二行中的第三个数据： 60\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "mya = np.array([11,25,36,89])\n",
    "myb = np.array([11,25,36,89],dtype=complex)\n",
    "myc = np.array([[11,25,36,89],[20,50,60,90]])\n",
    "print(mya)\n",
    "print(\"使用for循环：\")\n",
    "for a in myb:\n",
    "    print(a)\n",
    "print(\"显示二维数组中的数据：\\n\",myc)\n",
    "print(\"\\n第二行中的第三个数据：\",myc[1][2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9110098d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "zeros一维数组：\n",
      " [0. 0. 0. 0. 0. 0. 0. 0.]\n",
      "[[0 0 0 0]\n",
      " [0 0 0 0]\n",
      " [0 0 0 0]\n",
      " [0 0 0 0]]\n",
      "[[1. 1. 1. 1.]\n",
      " [1. 1. 1. 1.]\n",
      " [1. 1. 1. 1.]\n",
      " [1. 1. 1. 1.]\n",
      " [1. 1. 1. 1.]\n",
      " [1. 1. 1. 1.]]\n",
      "empty二维数组：\n",
      " [[0. 0. 0. 0.]\n",
      " [0. 0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "mya = np.zeros(8)\n",
    "print(\"zeros一维数组：\\n\",mya)\n",
    "myb = np.zeros((4,4),dtype=np.int64)\n",
    "myc = np.ones((6,4))\n",
    "myd = np.empty((2,4))\n",
    "print(myb)\n",
    "print(myc)\n",
    "print(\"empty二维数组：\\n\",myd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9e7e050c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "等差数列数组为： [ 1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47\n",
      " 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95\n",
      " 97 99]\n",
      "(array([1, 1, 2, 3, 4, 4, 5, 6, 7, 8]), 0.7777777777777778)\n",
      "[1 1 2 3 4 5 6 7 8 9]\n",
      "(array([1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]), 0.9)\n"
     ]
    }
   ],
   "source": [
    "#序列数组\n",
    "import numpy as np\n",
    "numpy1 = np.arange(1,100,2)\n",
    "print(\"等差数列数组为：\",numpy1)\n",
    "numpy2 = np.linspace(1,8,10,endpoint=True,retstep=True,dtype=int)\n",
    "numpy3 = np.linspace(1,10,10,endpoint=False,dtype=int)\n",
    "numpy4 = np.linspace(1,10,10,endpoint=False,retstep=True)\n",
    "print(numpy2)\n",
    "print(numpy3)\n",
    "print(numpy4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3046491c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数组的加法： [ 7 14 21]\n",
      "数组的减法： [ 7 14 21]\n",
      "数组的乘法： [10 40 90]\n",
      "数组的除法： [2.5 2.5 2.5]\n",
      "数组的乘方： [ 25 100 225]\n",
      "数组的点乘运算： 140\n",
      "数组大小比较： [ True  True  True]\n",
      "numpy1数组的最大值： 15\n",
      "numpy1数组的最小值： 2\n",
      "numpy1数组的和： 30\n",
      "numpy1和numpy2数组的和:  42\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "numpy1 = np.array([5,10,15])\n",
    "numpy2 = np.array([2,4,6])\n",
    "print(\"数组的加法：\",numpy1+numpy2)\n",
    "print(\"数组的减法：\",numpy1+numpy2)\n",
    "print(\"数组的乘法：\",numpy1*numpy2)\n",
    "print(\"数组的除法：\",numpy1/numpy2)\n",
    "print(\"数组的乘方：\",numpy1**2)\n",
    "print(\"数组的点乘运算：\",np.dot(numpy1,numpy2))\n",
    "print(\"数组大小比较：\",numpy1>=numpy2)\n",
    "print(\"numpy1数组的最大值：\",numpy1.max())\n",
    "print(\"numpy1数组的最小值：\",numpy2.min()) \n",
    "print(\"numpy1数组的和：\",numpy1.sum())\n",
    "print(\"numpy1和numpy2数组的和: \",numpy1.sum()+numpy2.sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ee4fc622",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "矩阵数据内容\n",
      "[[12 14 26]\n",
      " [31 38 53]]\n",
      "矩阵的转置后的数据内容：\n",
      "[[12 31]\n",
      " [14 38]\n",
      " [26 53]]\n",
      "[[1016 2282]\n",
      " [2282 5214]]\n",
      "[[-0.09092325  0.04573971]\n",
      " [-0.15261402  0.07408231]\n",
      " [ 0.16260289 -0.06100111]]\n",
      "------------\n",
      "返回两个数组的点积：\n",
      "[[37 40]\n",
      " [85 92]]\n"
     ]
    }
   ],
   "source": [
    "#矩阵\n",
    "import numpy as np\n",
    "numpy1 = np.matrix([[12,14,26],[31,38,53]])\n",
    "print(\"矩阵数据内容\")\n",
    "print(numpy1)\n",
    "numpy2 = numpy1.T\n",
    "print(\"矩阵的转置后的数据内容：\")\n",
    "print(numpy2)\n",
    "print(numpy1*numpy2)\n",
    "numpy3 = numpy1.I\n",
    "print(numpy3)\n",
    "print(\"------------\")\n",
    "a = np.array([[1,2],[3,4]])\n",
    "b = np.array([[11,12],[13,14]])\n",
    "print(\"返回两个数组的点积：\")\n",
    "print(np.dot(a,b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "10cf5354",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    a\n",
      "1    b\n",
      "2    c\n",
      "3    d\n",
      "dtype: object\n",
      "--------------\n",
      "100         C\n",
      "101       C++\n",
      "102    Python\n",
      "103      Java\n",
      "dtype: object\n",
      "------------\n",
      "a         C\n",
      "b       C++\n",
      "c    Python\n",
      "d      Java\n",
      "e      HTML\n",
      "dtype: object\n",
      "C\n",
      "Python\n",
      "b     C++\n",
      "d    Java\n",
      "dtype: object\n",
      "a         C\n",
      "b       C++\n",
      "c    Python\n",
      "dtype: object\n",
      "c    Python\n",
      "d      Java\n",
      "e      HTML\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "mydata1 = np.array(['a','b','c','d'])\n",
    "mys = pd.Series(mydata1)\n",
    "print(mys)\n",
    "print(\"--------------\")\n",
    "mydata2 = np.array(['C','C++','Python','Java'])\n",
    "myt = pd.Series(mydata2,index=[100,101,102,103])\n",
    "print(myt)\n",
    "print(\"------------\")\n",
    "s = pd.Series(['C','C++','Python','Java','HTML'],index=['a','b','c','d','e'])\n",
    "print(s)\n",
    "print(s[0])\n",
    "print(s['c'])\n",
    "print(s[['b','d']])\n",
    "print(s[:3])\n",
    "print(s[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d637a29a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              A    B    C    D    E    F\n",
      "2021-10-09  663  190  897   78  562  407\n",
      "2021-10-10  176  875  565  645  581  161\n",
      "2021-10-11  865  980  617  174  374  666\n",
      "2021-10-12   32  957   34  652  458  859\n",
      "2021-10-13  631  838  794   69  187  419\n",
      "2021-10-14  345  371  331  388  973  998\n",
      "2021-10-15  167  529  268  304  751  479\n",
      "2021-10-16  446  597  808  151   73  268\n",
      "2021-10-17  117  305  270  657  174  169\n",
      "2021-10-18  938  834  951  366   49  433\n",
      "2021-10-19  589  506  608  408  385  189\n",
      "2021-10-20  957  870  312  351  853  929\n",
      "2021-10-21  625  155  505  761   62  887\n",
      "2021-10-22  297  450  169  699  448  791\n",
      "2021-10-23  479  270   32  627  704   67\n",
      "2021-10-24  512  269   32  659  994  404\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "tsdf = pd.DataFrame(np.random.randint(10,1000,size=(16,6)),columns=['A','B','C','D','E','F'],index=pd.date_range('10/9/2021',periods=16))\n",
    "print(tsdf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca7b2d14",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
